<!DOCTYPE html>

<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'WechatSDK' . DIRECTORY_SEPARATOR . 'Lib' . DIRECTORY_SEPARATOR . 'Tools.php');
$menu = array(
    0 => array( 
        'name' => '推送消息',
        'sub_button' => array(
            array(
                'name' => '被动图文',
                'type' => 'click',
                "key" => "V1002_NEWS",
            ),
            array(
                'name' => '素材图文',
                'type' => 'media_id',
                "media_id" => "tm0D20ZrIxNCja3xm6dVBYVj_afcY7_6wiJtc1haObI",
            ),
            array(
                'name' => '素材图片',
                'type' => 'media_id',
                "media_id" => "tm0D20ZrIxNCja3xm6dVBSNGr9jt1rBhgF_b3sBTZv0",
            ),
            array(
                'name' => '素材音乐',
                'type' => 'media_id',
                "media_id" => "tm0D20ZrIxNCja3xm6dVBdvuVG1U1uCQYs5TSfod75g",
            ),
            array(
                'name' => '素材视频',
                'type' => 'media_id',
                "media_id" => "tm0D20ZrIxNCja3xm6dVBWLzSXH5XJ0P4NksH0T8rHE",
            ),
//                     array(
//                     'name' => '图文消息',
//                    'type' => 'view_limited',
//                    "key" => "MEDIA_ID2",
//                ),
        )
    ),
    1 => array(
        'name' => '自动回复',
        'sub_button' => array(
            array(
                "type" => "view",
                "name" => "搜索",
                "url" => "http://www.soso.com/"
            ),
            array(
                "type" => "pic_sysphoto",
                "name" => "系统拍照发图",
                "key" => "rselfmenu_1_0",
            ),
            array(
                "type" => "pic_photo_or_album",
                "name" => "拍照或者相册发图",
                "key" => "rselfmenu_1_1",
            ),
            array(
                "type" => "pic_weixin",
                "name" => "微信相册发图",
                "key" => "rselfmenu_1_2",
//                ),
            )
        )
    ),
    2 => array(
        'name' => '扫码与位置',
        'sub_button' =>
        array(
            array(
                "type" => "scancode_push",
                "name" => "扫码推事件",
                "key" => "rselfmenu_0_1",
            ),
            array(
                "type" => "scancode_waitmsg",
                "name" => "扫码带提示",
                "key" => "rselfmenu_0_0",
            ),
            array(
                'type' => 'location_select',
                'name' => '发送位置',
                "key" => "rselfmenu_2_0",
            ),
        )
    ),
);
$forever_articles = array('articles'=>array(
                array(
                   'title' =>'永久图文素材' ,
                    'thumb_media_id' =>'tm0D20ZrIxNCja3xm6dVBb2pC6zKhFxLoUgnxkHuzEg' ,
                    
                    'author' =>'作者' ,
                    'digest' =>'图文消息的摘要' ,
                    'show_cover_pic' =>1 ,
                    'content' =>'图文消息的具体内容' ,
                    'content_source_url' =>'http://www.weipai.cn/index.do' ,
                ),
            array(
                   'title' =>'永久图文素材' ,
                    'thumb_media_id' =>'tm0D20ZrIxNCja3xm6dVBccZzqGewDwzHAgEtOZYha8' ,
                    'author' =>'作者' ,
                    'digest' =>'图文消息的摘要' ,
                    'show_cover_pic' =>0 ,
                    'content' =>'图文消息的具体内容' ,
                    'content_source_url' =>'https://www.huxiu.com/' ,
                ),
            
            ));
$update_forever_articles = array(
             'articles'=>array(
                   'title' =>'标题xx',
                    'thumb_media_id' =>'tm0D20ZrIxNCja3xm6dVBSNGr9jt1rBhgF_b3sBTZv0' ,
                    'author' =>'作者' ,
                    'digest' =>'图文消息的摘要' ,
                    'show_cover_pic' =>true ,
                    'content' =>'图文消息的具体内容' ,
                    'content_source_url' =>'http://www.weipai.cn/index.do' ,
            ),
             'media_id' => 'tm0D20ZrIxNCja3xm6dVBSx9GF1AtiNWi181fk4crQs',
             'index' => 0,
             );
$articles_data = array(
             'artiles'=>array(
                array(
                   'title' =>'永久图文素材' ,
                    'thumb_media_id' =>'R6bwfmZymlz_CpTUH7nzYryddl8t3hVJwErYRJ0suhQ3Ky_PN-1lGfYU10WopAI5' ,
                    
                    'author' =>'作者' ,
                    'digest' =>'图文消息的摘要' ,
                    'show_cover_pic' =>1 ,
                    'content' =>'图文消息的具体内容' ,
                    'content_source_url' =>'http://www.weipai.cn/index.do' ,
                ),
            array(
                   'title' =>'永久图文素材' ,
                    'thumb_media_id' =>'pKwcNc1t4-pScqphYLSs2zlkPuO-_eNnX3NK0nQ_tKXuSgF_RZiNOk2rdaCJVE0b' ,
                    'author' =>'作者' ,
                    'digest' =>'图文消息的摘要' ,
                    'show_cover_pic' =>0 ,
                    'content' =>'图文消息的具体内容' ,
                    'content_source_url' =>'https://www.huxiu.com/' ,
                ),
            )
            );
$upload_mp_video = array(
    'media_id'=>'gmfNUNgjsQArTiQnsUGsTRMZDvpKPS68_8IIC1mfF69Su_-cFMCiQ00x3TTsk5aD',
    'title'=>'群发素材',
    'description'=>'群发视频需要用到的素材'
);
$tpl_data['setIndustry'] = array(
            'industry_id1'=>1,
            'industry_id2'=>4,
        );
$tpl_data['addMessage'] = array('template_id_short' => 'TM00015');
$tpl_data['sendMessage'] = array(
            'touser' => 'oYVyYw2BzLX8eJ1I-oCDSN6z4avI',
            'template_id' => 'Zx-REWtsUGEdSZcmXhso9OKhieCwguItXXGw-rHv16c',
            'url' => 'http://www.baidu.com',
            'data' => array(
                'first' => array(
                    'value' => '恭喜你购买成功',
                    'color' => '#173177',
                )
            )
        );
$custom['account']['addKfaccount'] =  array("kf_account" => 'test1@test', "nickname" => '客服1', "password" => md5('123456'));
$custom['account']['updateKfaccount'] =  array("kf_account" => 'test1@test', "nickname" => '客服1', "password" => md5('123456'));
$custom['account']['deleteKfaccount'] = 'test1@test';
$custom['account']['setKfaccount'] = 'test1@test';
$custom['account']['inviteworker'] = array("kf_account" => 'test1@test', "invite_wx" => 'xx');

$custom['session']['createSession'] = array("openid" => 'test1@test', "kf_account" => 'test1@test','text'=>'xx');
$custom['session']['closeSession'] = array("openid" => 'test1@test', "kf_account" => 'test1@test','text'=>'xx');
$custom['session']['getSession'] = 'test1@test';
$custom['session']['getSessionList'] =  'test1@test';

$custom['message']['getRecordMessage'] = $data = array(
//             'starttime' =>'',
//             'endtime' =>'',
             'msgid' => 1,
             'number' => 1000,
         );
$custom['message']['sendtext'] = "Hello World";
$custom['message']['sendimage'] = "tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA";
$custom['message']['sendvoice'] = "tm0D20ZrIxNCja3xm6dVBUfveZgQA7LwcN5V8_L3-zE";
$custom['message']['sendvideo'] = array(
                'media_id'     => 'tm0D20ZrIxNCja3xm6dVBWLzSXH5XJ0P4NksH0T8rHE',
                'thumb_media_id'  => 'tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA',
                'title' => '客服发送音乐消息',
                'description'=> '这是发送的测试的消息',
        );
$custom['message']['sendmusic'] = array(
                'title'       => '标题xx',
                'description' => '描述xx',
                'musicurl'    => 'http://music.baidu.com/?fr=baiduwisehome&ssid=0&from=844b&uid=&pu=sz%401320_2001%2Cta%40iphone_1_10.3_3_603&bd_page_type=1',
                'hqmusicurl'  => 'http://music.baidu.com/?fr=baiduwisehome&ssid=0&from=844b&uid=&pu=sz%401320_2001%2Cta%40iphone_1_10.3_3_603&bd_page_type=1',
                'thumb_media_id'  => 'tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA'
            );
$custom['message']['sendnews'] = array(
            array(
                'title' => '标题xx',
                'description' => '描述xx',
                'url' => 'https://www.huxiu.com/',
                'picurl' => 'http://mmbiz.qpic.cn/mmbiz_jpg/aADO7uwnt54CQXvkLtQs36Jm2fuH0VkXIClM38YuspbaERkpULGmYDkYIdkDtgOEtaUyQp2e7P9kwicn9s4GicZw/0?wx_fmt=jpeg3'
            )
        );
$custom['message']['sendmpnews'] = 'tm0D20ZrIxNCja3xm6dVBVhURDYx6XVGeEnrpXOtHXs';





$mass['sendtext'] = "这是群发消息";
$mass['sendimage'] = "tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA";
$mass['sendvoice'] = "tm0D20ZrIxNCja3xm6dVBUfveZgQA7LwcN5V8_L3-zE";
$mass['sendvideo'] = array(
                'media_id'     => 'JMPnkAzL14MyfmnVacj2vJRPGDcD7AKWMhocdolzXgSAzJO47I5HD0y1G-LADj9W',
//                'thumb_media_id'  => 'tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA',
                'title' => '群发消息标题xx',
                'description'=> '群发消息描述xx',
        );
$mass['sendmpnews'] = 'Ij9hAhnHpqGF8ogBA3z01utIfb57-Ww5pJBSZD2cMjChTK9eur3tmQwQ92XC-bBz';

$oauth['getUserInfo'] = array(
               'access_token' =>'oYVyYw2BzLX8eJ1I-oCDSN6z4avI',
                'openid' =>'oYVyYw2BzLX8eJ1I-oCDSN6z4avI'
        );
$test_data = array(
    array(
        'name' => '获取access_token',
        'sub' => array(
            array('name' => '获取访问令牌', 'url' => '/access/getAccessToken', 'data' => ''),
           
        ),
    ),
    array(
        'name' => '微信菜单',
        'sub' => array(
            array('name' => '创建菜单', 'url' => '/menu/createMenu', 'data' => WechatSDK\Lib\Tools::json_encode($menu)),
            array('name' => '获取菜单', 'url' => '/menu/getMenu', 'data' => ''),
        ),
    ),
    array(
        'name' => '微信素材',
        'sub' => array(
            array('name' => '上传临时素材', 'url' => '/media/uploadMedia','data' => 'image'),
            array('name' => '获取临时素材', 'url' => '/media/getMedia', 'data' => 'ZAUvBWVCqafIu2hTkQH0cunXZrJkoiXsX1CHxSQsIuE_w7TshwOPl03VD8fPL-Ly'),
            array('name' => '上传永久素材', 'url' => '/media/uploadForeverMedia','data' => 'image'),
            array('name' => '获取永久素材', 'url' => '/media/getForeverMedia', 'data' => 'tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA'),
            array('name' => '删除永久素材', 'url' => '/media/delForeverMedia','data' => 'tm0D20ZrIxNCja3xm6dVBUCQ_mROTg40LY6sAzo56ck'),
            array('name' => '获取永久素材列表', 'url' => '/media/getForeverList', 'data' => 'image'),
            array('name' => '获取永久素材总数', 'url' => '/media/getForeverCount','data' => ''),
            array('name' => '上传图片', 'url' => '/media/uploadImg', 'data' => 'image'),
            array('name' => '上传永久图文素材', 'url' => '/media/uploadForeverArticles','data' =>WechatSDK\Lib\Tools::json_encode($forever_articles)),
            array('name' => '更新永久图文素材', 'url' => '/media/updateForeverArticles', 'data' =>WechatSDK\Lib\Tools::json_encode($update_forever_articles)),
            array('name' => '上传图文消息素材', 'url' => '/media/uploadArticles', 'data' => WechatSDK\Lib\Tools::json_encode($articles_data)),
            array('name' => '上传群发消息视频素材', 'url' => '/media/uploadMpVideo', 'data' => WechatSDK\Lib\Tools::json_encode($upload_mp_video)),
        ),
    ),
    array(
        'name' => '模板管理',
        'sub' => array(
            array('name' => '设置所属行业[权限]', 'url' => '/template/setIndustry','data' => WechatSDK\Lib\Tools::json_encode($tpl_data['setIndustry'])),
            array('name' => '添加消息模板[权限]', 'url' => '/template/addMessage', 'data' => WechatSDK\Lib\Tools::json_encode($tpl_data['addMessage'])),
            array('name' => '发送模板消息', 'url' => '/template/sendMessage','data' => WechatSDK\Lib\Tools::json_encode($tpl_data['sendMessage'])),
        ),
    ),
    array(
        'name' => '客服账号',
        'sub' => array(
            array('name' => '添加客服账号[权限]', 'url' => '/custom/addKfaccount','data' => WechatSDK\Lib\Tools::json_encode($custom['account']['addKfaccount'])),
            array('name' => '修改客服账号信息[权限]', 'url' => '/custom/updateKfaccount', 'data' => WechatSDK\Lib\Tools::json_encode($custom['account']['updateKfaccount'])),
            array('name' => '删除客服账号[权限]', 'url' => '/custom/deleteKfaccount','data' => WechatSDK\Lib\Tools::json_encode($custom['account']['deleteKfaccount'])),
             array('name' => '上传客服头像[权限]', 'url' => '/custom/setKfaccount','data' =>WechatSDK\Lib\Tools::json_encode($custom['account']['setKfaccount'])),
             array('name' => '获取多客服客服基本信息[权限]', 'url' => '/custom/getKflist','data' =>''),
             array('name' => '获取在线多客服客服基本信息[权限]', 'url' => '/custom/getOnlineKFlist','data' => ''),
             array('name' => '绑定多客服[权限]', 'url' => '/custom/inviteworker','data' => WechatSDK\Lib\Tools::json_encode($custom['account']['inviteworker'])),
            
        ),
    ),
    array(
        'name' => '客服会话',
        'sub' => array(
            array('name' => '创建指定多客服会话[权限]', 'url' => '/custom/createSession','data' => WechatSDK\Lib\Tools::json_encode($custom['session']['createSession'])),
            array('name' => '关闭指定多客服会话[权限]', 'url' => '/custom/closeSession', 'data' => WechatSDK\Lib\Tools::json_encode($custom['session']['closeSession'])),
            array('name' => '获取用户会话状态[权限]', 'url' => '/custom/getSession','data' => WechatSDK\Lib\Tools::json_encode($custom['session']['getSession'])),
             array('name' => '获取指定客服的会话列表[权限]', 'url' => '/custom/getSessionList','data' => WechatSDK\Lib\Tools::json_encode($custom['session']['getSessionList'])),
             array('name' => '获取未接入会话列表[权限]', 'url' => '/custom/getWait','data' => ''),
        ),
    ),
    array(
        'name' => '客服消息',
        'sub' => array(
            array('name' => '获取聊天记录[权限]', 'url' => '/custom/getRecordMessage','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['getRecordMessage'])),
            array('name' => '客服发消息[文本', 'url' => '/custom/sendtext', 'data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendtext'])),
            array('name' => '客服发消息[图片]', 'url' => '/custom/sendimage','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendimage'])),
             array('name' => '客服发消息[语音]', 'url' => '/custom/sendvoice','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendvoice'])),
            array('name' => '客服发消息[视频]', 'url' => '/custom/sendvideo','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendvideo'])),
             array('name' => '客服发消息[音乐]', 'url' => '/custom/sendmusic','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendmusic'])),
            array('name' => '客服发消息[图文]', 'url' => '/custom/sendnews','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendnews'])),
            array('name' => '客服发消息[图文]', 'url' => '/custom/sendmpnews','data' => WechatSDK\Lib\Tools::json_encode($custom['message']['sendmpnews'])),
            array('name' => '客服发消息[卡券]-[未调试]', 'url' => '/custom/sendwxcard','data' => ''),
        ),
    ),
     array(
        'name' => '群发消息',
        'sub' => array(
            array('name' => '群发消息[文本]', 'url' => '/Mass/sendtext', 'data' => WechatSDK\Lib\Tools::json_encode($mass['sendtext'])),
            array('name' => '群发消息[图片]', 'url' => '/Mass/sendimage','data' => WechatSDK\Lib\Tools::json_encode($mass['sendimage'])),
             array('name' => '群发消息[语音]', 'url' => '/Mass/sendvoice','data' =>WechatSDK\Lib\Tools::json_encode($mass['sendvoice'])),
            array('name' => '群发消息[视频]', 'url' => '/Mass/sendvideo','data' =>WechatSDK\Lib\Tools::json_encode($mass['sendvideo'])),
            array('name' => '群发消息[图文]', 'url' => '/custom/sendmpnews','data' =>WechatSDK\Lib\Tools::json_encode($mass['sendnews'])),
            array('name' => '群发消息删除', 'url' => '/custom/del','data' => '1000000007'),
            array('name' => '群发消息预览', 'url' => '/custom/preview','data' => 'sendtext'),
            array('name' => '群发消息查询', 'url' => '/custom/query','data' => ''),
        ),
    ),
     array(
        'name' => '授权登陆Oauth2.0',
        'sub' => array(
            array('name' => '授权跳转接口', 'url' => '/Oauth/getRedirect', 'data' => 'http://www.51kuangquanshui.com'),
            array('name' => '获取授权access_token', 'url' => '/Oauth/getAccessToken','data' => '061X07ir0BNt8c1iIhjr0wn8ir0X07iv'),
             array('name' => '刷新access token并续期', 'url' => '/Oauth/getRefreshToken','data' => 'teEBX3BfeGjaDTXIUUo_yzy5CHolB-h7LbXmcQN0ynyZNjROFGptuT0UTLv6RZgVI_41AlMADHurjhgEizeCau9bp3cXS6c_-n70znP4vsw'),
            array('name' => '获取授权后的用户资料', 'url' => '/Oauth/getUserInfo','data' => WechatSDK\Lib\Tools::json_encode($oauth['getUserInfo'])),
        ),
    ),
     array(
        'name' => '群发消息',
        'sub' => array(
            array('name' => '获取JSAPI授权TICKET', 'url' => '/Script/getJsTicket', 'data' => ''),
            array('name' => '获取JsApi使用签名', 'url' => '/Script/getJsSign','data' => 'http://www.baidu.com'),
        ),
    ),
    array(
        'name' => '用户管理',
        'sub' => array(
            array('name' => '获取用户基本信息', 'url' => '/user/getUserInfo', 'data' => ''),
            array('name' => '获取用户基本信息', 'url' => '/user/getUserList', 'data' => ''),
           
        ),
    ),
);
?>
<html>
    <head>
        <title>这是微信SDK组件的测试页面</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!--<script src="http://code.jquery.com/jquery-latest.js"></script>-->
        <script src="/web/static/js/jquery.js"></script>
    </head>
    <body>
        <style type="text/css">  
            table.gridtable {  
                font-family: verdana,arial,sans-serif;  
                font-size:11px;  
                color:#333333;  
                border-width: 1px;  
                border-color: #666666;  
                border-collapse: collapse; 
                margin: 20px;
            }  
            table.gridtable th {  
                border-width: 1px;  
                padding: 8px;  
                border-style: solid;  
                border-color: #666666;  
                background-color: #dedede;  
            }  
            table.gridtable td {  
                border-width: 1px;  
                padding: 8px;  
                border-style: solid;  
                border-color: #666666;  
                background-color: #ffffff;  
            } 
            .btn.blue { background: #2ae; padding: 10px 30px 10px 30px; } 
            .response_dat { width: 150px;}
            textarea{margin: 0px; height: 50px; width: 478px;}
        </style>  
        <table class="gridtable">
            <tbody>
                <tr>
                    <th>类目</th>
                    <th>序号</th>
                    <th>接口</th>
                    <th>参数</th>
                    <th>操作</th>
                    <th>响应</th>
                </tr>
<?php foreach ($test_data as $key => $val) { ?>
                    <?php foreach ($val['sub'] as $kk => $vv) { ?>
                        <tr>
                        <?php if ($kk == 0) { ?><td rowspan="<?php echo count($val['sub']); ?>"> <?php echo $val['name'] ?></td><?php }; ?>
                            <td><?php echo $kk + 1; ?></td>
                            <td><a href="<?php echo $vv['url']; ?>"><?php echo $vv['name']; ?></a></td>
                            <td><?php if ($vv['data']) { ?><textarea ><?php echo $vv['data']; ?></textarea> <?php }; ?> </td>
                            <td ><input type="button" class="btn blue test" value="<?php echo $vv['url']; ?>" > </td>
                            <td class="response_dat"></td>
                        </tr>
    <?php }; ?>
                <?php }; ?>
            <input type="hidden" name="access_token" id="access_token" value=""/>
            </tbody>
        </table>
    </body>
</html>
<div style="width:66px;height:66px;position:fixed;top:50%;left:50%;margin-left: -33px;margin-top: -33px;" id="loadgif">
    <img  alt="加载中..." src="/load.gif" style="width: 100%;"/>
</div>
<script type="text/javascript">
    $(document).ready(function () {
          $("#loadgif").hide();
        $(".test").on("click", function () {
             $("#loadgif").show();
             var access_token = $("#access_token").val();
             var is_get_access_token = 0;
             if(!access_token){
                  is_get_access_token =1;
                 alert('请先获取access_token');
             }
            var n_rep = $(this).parent().next();
            var p_val = $(this).parent().prev().find('textarea').val();


            var p_url = $(this).val();
//            console.log(p_val);
//            return ;
//            console.log(p_val);

            $.ajax({
                type: "POST",
                url: p_url,
                data: {'param': p_val},
                dataType: "json",
//                contentType: "application/json",
                success: function (data) {
                     $("#loadgif").hide();
                    var data_str = JSON.stringify(data);
//                   console.log(typeof(aa));
                    if(is_get_access_token){
                         $("#access_token").val(data_str)
                    }
                    n_rep.html(data_str);
                }
                
            });
        })
    });
</script>
